package com.ujs.edu.demo.dao;

import com.ujs.edu.demo.dataobject.BcBooks;
import com.ujs.edu.demo.dataobject.BcCollect;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface BcCollectMapper {
    @Delete({
        "delete from bc_collect",
        "where collectId = #{collectid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer collectid);

    @Insert({
        "insert into bc_collect (collectId, bookId, ",
        "createtime, modifytime, ",
        "memberId)",
        "values (#{collectid,jdbcType=INTEGER}, #{bookid,jdbcType=INTEGER}, ",
        "now(), now(), ",
        "#{memberid,jdbcType=INTEGER})"
    })
    int insert(BcCollect record);

    @Select({
        "select",
        "collectId, bookId, createtime, modifytime, memberId",
        "from bc_collect",
        "where collectId = #{collectid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="collectId", property="collectid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bookId", property="bookid", jdbcType=JdbcType.INTEGER),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="memberId", property="memberid", jdbcType=JdbcType.INTEGER)
    })
    BcCollect selectByPrimaryKey(Integer collectid);

    @Select({
        "select",
        "collectId, bookId, createtime, modifytime, memberId",
        "from bc_collect"
    })
    @Results({
        @Result(column="collectId", property="collectid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bookId", property="bookid", jdbcType=JdbcType.INTEGER),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="memberId", property="memberid", jdbcType=JdbcType.INTEGER)
    })
    List<BcCollect> selectAll();

    //多对多筛选
    @Select("select * from bc_collect")
    @Results({
            @Result(column="collectId", property="collectid", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bookId", property="bookid", jdbcType=JdbcType.INTEGER),
            @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="memberId", property="memberid", jdbcType=JdbcType.INTEGER),
            @Result(property = "books",column = "collectId",
                             many = @Many(select = "com.ujs.edu.demo.dao.BcBooksMapper.selectByPrimaryKey",
                                     fetchType = FetchType.LAZY))
    })
    List<BcCollect> selectByMany();

    @Update({
        "update bc_collect",
        "set bookId = #{bookid,jdbcType=INTEGER},",
          "modifytime = now(),",
          "memberId = #{memberid,jdbcType=INTEGER}",
        "where collectId = #{collectid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(BcCollect record);
}